package br.com.hsp.system.beans;

import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.bean.ViewScoped;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.persistence.EntityManager;
import javax.servlet.http.HttpServletRequest;

import br.com.hsp.organizacao.Instituicao;
import br.com.hsp.system.repository.InstituicaoRepository;
import br.com.hsp.system.repository.UserRepository;

@ManagedBean
@ViewScoped
public class LogAIBean {
	
	private Instituicao instituicao;
	
	public LogAIBean(){
		
	}

	public void verificaTipoUser() {
		EntityManager manager = this.getManager();
		UserRepository repository = new  UserRepository(manager);
		
		
	}
	
	private EntityManager getManager() {
		FacesContext fc = FacesContext.getCurrentInstance();
		ExternalContext ec = fc.getExternalContext();
		HttpServletRequest request = (HttpServletRequest) ec.getRequest();
		return (EntityManager) request.getAttribute("EntityManager");

	}
	
	//TODO 
	//MUDAR PARA PEGAR A INSTIUIÇÃO ONDE A ATENDENTE TRABALHA
	public List<Instituicao> getInstituicoes() {
		List<Instituicao> instituicoes;
		EntityManager manager = this.getManager();
		InstituicaoRepository instituicaoRepository = new InstituicaoRepository(manager);
		instituicoes = instituicaoRepository.getClinica("HC clinica");
		this.instituicao = instituicoes.get(0);
		return instituicoes;
	}

	public Instituicao getInstituicao() {
		return instituicao;
	}

	public void setInstituicao(Instituicao instituicao) {
		this.instituicao = instituicao;
	}
	

	
	
	
}
